#include <stdio.h>
#include <algorithm>
using namespace std;

typedef struct skier {
	double time;
	int num;
} Skier;

int n, m;
Skier round1[110];
Skier round2[110];
char sig;

bool cmp(Skier a, Skier b) {
	return a.time < b.time;
}

int main() {
	scanf("%d %d", &n, &m);

	scanf("%lf", &round1[0].time);
	round1[0].num=1;

	for (int i=1; i<n; i++) {
		scanf(" %c%lf", &sig, &round1[i].time);
		
		if (sig=='+') round1[i].time = round1[i].time+round1[0].time;
		else round1[i].time = round1[0].time - round1[i].time;

		round1[i].num=i+1;
		sort(round1, round1+i+1, cmp);
	}

	scanf("%lf", &round2[0].time);
	round2[0].num = round1[m-1].num;

	for (int i=1; i<m; i++) {
		scanf(" %c%lf", &sig, &round2[i].time);

		if (sig=='+') round2[i].time = round2[i].time+round2[0].time;
		else round2[i].time = round2[0].time-round2[i].time;

		round2[i].num = round1[m-1-i].num;
		sort(round2, round2+i+1, cmp);
	}
	
	for (int i=0; i<3; i++)
		printf("%d\n", round2[i].num);

	return 0;
}
